package complex;

public class Complex {
	
	private double x;
	private double y;
	
	public Complex(double x, double y){
		this.x = x;
		this.y = y;
	}
	
	public double getX(){
		return x;
	}
	
	public double getY(){
		return y;
	}
	
	public Complex add(Complex b){
		return new Complex(x + b.getX(), y + b.getY());
	}
	
	@Override
	public boolean equals(Object that) {
		if(this == that) return true;
		if(!(that instanceof Complex)) return false;
		
		Complex b = (Complex) that;
		return (x == b.getX()) && (y == b.getY());
		
	}
	
	@Override
	public int hashCode() {
		 return (int) (42 * (69 + x) + y);
	}
	
	@Override
	public String toString() {
		return "< "+x+", "+y+" >";
	}

	public Complex sub(Complex b) {
		return new Complex(x - b.getX(), y - b.getY());
	}

	public Complex neg() {
		return new Complex(-x, -y);
	}

	public double abs() {
		return Math.sqrt(x * x + y * y);
	}

	public Complex mult(Complex b) {
		double real = x*b.getX() - y*b.getY();
		double imag = x*b.getY() + y*b.getX();
		return new Complex(real, imag);
	}

	//TODO: arg() is a little different depending on which
	//		quadrant in C, z is in.
	public double arg() {
		return Math.atan2(y, x);
	}

	public Complex conj() {
		return new Complex(x, -y);
	}

	public Complex reciprocal() {	
		return new Complex(conj().getX()/(x*x + y*y), conj().getY()/(x*x + y*y));
	}

	public Complex div(Complex b) {
		double bottom = b.getX()*b.getX() + b.getY()*b.getY();
		double real = x*b.getX() + y*b.getY();
		double imag = -x*b.getY() + y*b.getX();
		return new Complex(real/bottom, imag/bottom);
	}

	public Complex scale(double scalar) {
		return new Complex(x*scalar, y*scalar);
	}
	
	
}
